package com.zf.zfed.audit.tools

import android.app.Activity
import com.zf.zfed.audit.ui.Navigation
import com.zf.zfed.audit.ui.ZFHomeActivity

object ActivityCollector {
    private val activities = ArrayList<Activity>()

    fun addActivity(activity: Activity) {
        activities.add(activity)
    }

    fun removeActivity(activity: Activity) {
        activities.remove(activity)
    }

    fun finishAll() {
        for (activity in activities) {
            if (!activity.isFinishing) {
                activity.finish()
            }
        }
        activities.clear()

        // 导航情况
        Navigation.clear()

        // 视图收集器清空
        ViewManager.clear()

        // 关闭通道
        // 杀掉当前进程 killProcess()方法只能用于杀掉当前程序的进程，不能用于杀掉其他程序。
        // android.os.Process.killProcess(android.os.Process.myPid())
    }

    fun rootActivity(): ZFHomeActivity = activities.getOrNull(0) as ZFHomeActivity
}